package com.hmall.mapper;

import com.hmall.model.MallOrder;
import com.hmall.util.MyMapper;
import com.hmall.vo.MallOrderManageVo;
import com.hmall.vo.OrderSelectItemVo;
import com.hmall.vo.OrderSelectVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.List;

@Repository
public interface MallOrderMapper extends MyMapper<MallOrder> {
    MallOrder selectByUserIdAndOrderNo(@Param("userId") Integer userId, @Param("orderNo") Long orderNo);

    MallOrder selectByOrderNo(Long orderNo);

    List<MallOrder> selectByUserId(Integer userId);

    List<MallOrder> selectAllOrder();

    List<MallOrderManageVo> selectOrder();

    List<MallOrderManageVo> selectSHZOrder(@Param("dept_id") Integer dept_id);

    List<MallOrderManageVo> selectWFKOrder(@Param("dept_id") Integer dept_id);

    List<MallOrderManageVo> selectYQXOrder(@Param("dept_id") Integer dept_id);

    List<MallOrderManageVo> selectYFKOrder(@Param("dept_id") Integer dept_id);

    List<MallOrderManageVo> selectYFHOrder(@Param("dept_id") Integer dept_id);

    List<MallOrderManageVo> selectJYCGOrder(@Param("dept_id") Integer dept_id);

    List<MallOrderManageVo> selectWQHTOrder(@Param("dept_id") Integer dept_id);

    List<MallOrderManageVo> selectHTSXOrder(@Param("dept_id") Integer dept_id);

    Integer cancelOrder(Integer id);

    Integer deliverOrder(Integer id);

    Integer updatePayment(@Param("orderId") Integer orderId, @Param("change_price") BigDecimal change_price);

    Integer updateOrder(@Param("id") Integer id, @Param("shipping_id") Integer shipping_id, @Param("distCode") Integer distCode);

    int updateByOrderId(String status, Integer orderId);

    int updateByOrderNo(@Param("status") Integer status, @Param("order_no") Long order_no);
    //创建订单
    int insertOrder(@Param("order") MallOrder order);
    //批量创建订单
    int batchInsertOrder(@Param("orderList") List<OrderSelectVo> orderList);

    //查询最近三个月订单
     List<OrderSelectVo> selectOrderItemsByThreeMonth(
             @Param("status") String status,
             @Param("userId") Integer userId,
             @Param("startPage") Integer startPage,
             @Param("pageSize") Integer pageSize
     ) ;
    //查询最近三个月所有订单
     List<OrderSelectVo> selectAllOrderItemsByThreeMonth(

             @Param("userId") Integer userId,
             @Param("startPage") Integer startPage,
             @Param("pageSize") Integer pageSize
     ) ;
    //订单号查询订单
     OrderSelectVo selectOrderByOrderNo(@Param("oderNo") Long oderNo) ;
     //查询某个订单下的产品列表
    List<OrderSelectItemVo> selectOrderItemsByOrderNo(@Param("orderNo") Long orderNo);
    int selectOrderByThreeMonthCount(@Param("status") String status,
                                     @Param("userId") Integer userId);
    int selectAllOrderByThreeMonthCount(
            @Param("userId") Integer userId);

    //列出状态为50(交易成功) 的所有订单编号
    List<BigInteger> listSuccessOrderNo(@Param("SUCCESS") int SUCCESS);

    //列出状态为50（交易成功）的某个用户的所有订单编号
    List<BigInteger> listSuccessUserOrderNo(@Param("userId") Integer userId, @Param("SUCCESS") int success);

    //列出状态为50(交易成功)的更新时间
    Date selectUpdateTime(@Param("status") int status, @Param("productId") Integer productId);

    //删除某个用户的所有订单
    void deleteByUserId(@Param("userId") Integer userId);

    void changeOrderStatus(@Param("orderId") Integer orderId, @Param("status") Integer status);

    List<MallOrder> findOrderStatus(@Param("userId") Integer userId);

    //列出某个订单详情的所有编号
    List<BigInteger> listOrderNoList(@Param("orderId") Integer order_id);

    //查询是否有某个订单
    int selectCountByOrderId(@Param("orderId") Integer orderId);

    List<MallOrder> selectNoComment(@Param("userId") Integer userId);

    //查询商铺id
    Integer selectShopIdByOrderId(@Param("orderId") Integer order_id);

    int selectOrderCountByStatusAndUserId(@Param("userId") Integer userId, @Param("status") int status);

    List<BigInteger> selectSampleNoByUserId(@Param("userId") Integer userId);

    List<Long> selectOrderNoListByUserIdAndStatus(@Param("userId") Integer userId, @Param("status") int i);

    BigDecimal getPaymentByUserIdList(@Param("userIdList") List<Integer> userIdList, @Param("havePay") int havePay, @Param("haveSend") int haveSend,
                                      @Param("haveFinish") int haveFinish, @Param("startDate") Date startDate, @Param("endDate") Date endDate);


    List<Long> selectSomeLatestOrderNoByIdList(@Param("count") int count, @Param("customerUserIdList") List<Integer> customerUserList, @Param("havePay") int havePay, @Param("haveSend") int haveSend,
                                               @Param("haveFinish") int haveFinish);

    Integer selectOrderCountByUserIdList(@Param("customerUserList") List<Integer> customerUserList, @Param("havePay") Integer have_pay, @Param("haveSend") Integer have_send,
                                         @Param("haveFinish") Integer have_finish);

    List<MallOrder> selectBySalesmanIdListWithStatus(@Param("salesmanIdList") List<Integer> salesmanIdList, @Param("customerId") Integer customerId, @Param("status") Integer status);

    void changeOrderStatusByOrderNo(@Param("orderNo") Long orderNo, @Param("status") Integer status, @Param("payment") BigDecimal payment);

    MallOrder selectAllByOrderNo(@Param("orderNo") Long orderNo);

    String selectUserNameByOrderNo(@Param("orderNo") Long orderNo);

    void myUpdatePayment(@Param("id") Integer id, @Param("payment") BigDecimal payment);

    List<MallOrder> selectOrderIdByUserIdList(@Param("customerUserIdList") List<Integer> customerUserIdList);

    List<MallOrder> selectHaveSendAndFinished(@Param("start") Date start, Date end, Integer customerId);

    void updateStatusByOrderNo(@Param("orderNo") Long orderNo, @Param("status") int i);

    Integer selectSimpleOrderByUserId(@Param("userId") Integer userId);

    List<MallOrder> selectPassOrderByCustomerId(@Param("customerId") Integer customerId);

    List<MallOrder> selectByUserIdWithStatus(@Param("userId") Integer userId);

    List<MallOrder> selectByDealerId(@Param("fStatus") Integer fStatus, @Param("dealerIdList") List<Integer> dealerIdList);

    List<MallOrder> selectByDealerIdAndRoleStatus(@Param("dealerIdList") List<Integer> dealerIdList, @Param("status") Integer status, @Param("deptId") Integer deptId, @Param("start") Integer start,
                                                  @Param("end") Integer end, @Param("fStatus") Integer fStatus);

    void updateRoleStatusWithOrderNo(@Param("orderNo") Long orderNo, @Param("status") Integer status, @Param("deptId") Integer deptId);

    int selectCountByDealerIdAndRoleStatus(@Param("dealerIdList") List<Integer> dealerIdList, @Param("status") Integer status, @Param("deptId") Integer deptId, @Param("fStatus") Integer fStatus);

    void updateStatus1(@Param("status1") int i, @Param("orderNo") Long orderNo);

    void updateSendDate(@Param("orderNo") Long orderNo, @Param("sendDate") String sendDate);

    void myInsert(@Param("order") MallOrder mallOrder);

    void updateStatus2(@Param("status") int i, @Param("orderNo") Long orderNo);

    void updateStatus3(@Param("status") int i, @Param("orderNo") Long orderNo);

    void updatePaymentWithOrderNo(@Param("orderNo") Long orderNo, @Param("allPrice") BigDecimal allPrice);

    void updateOtherArgs(@Param("salesOrganization") String salesOrganization, @Param("salesType") String salesType,
                         @Param("freightPaymentType") String freightPaymentType, @Param("paymentMethods") String paymentMethods, @Param("orderNo") Long orderNo);

    Long selectLatestOrderNo(@Param("customerUserId") Integer customerUserId);

    List<MallOrder> selectOrderWithDetail(@Param("orderList") List<MallOrder> orderList);

    /**
     * 根据时间得到订单列表
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @Param customerUserIdList
     * @return List<MallOrder>
     */
    List<MallOrder> selectOrderByTime(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("customerUserIdList") List<Integer> customerUserIdList);

    /**
     * 根据公司得到最总交易金额
     * @param customerId 公司id
     * @return BigDecimal
     */
    BigDecimal selectTotalTradePaymentByCustomerId(@Param("customerId") Integer customerId, @Param("mallOrderList") List<MallOrder> mallOrderList);

    /**
     * 根据公司得到总订单重量
     * @param customerId 公司id
     * @return BigDecimal
     */
    BigDecimal selectTotalTradeWeightByCustomerId(@Param("customerId") Integer customerId, @Param("mallOrderList") List<MallOrder> mallOrderList);

    /**
     * @Date 2019/1/14 17:17
     * @Param [start, end, customerId]
     * @return java.util.List<java.lang.Long>
     * @Description 根据公司id和时间限制返回订单编号列表
     */
    List<Long> selectByCustomerIdWithTime(@Param("start") Date start, @Param("end") Date end, @Param("customerId") Integer customerId);


//    List<MallOrder> selectOrderIdByUserIdListWithDetail(@Param("customerUserIdList") List<Integer> customerUserIdList);
}